package cn.net.shuxing.yifu.common.service;

import cn.net.shuxing.yifu.common.bean.ContentHelper;
import cn.net.shuxing.yifu.common.bean.ContentQuestion;
import cn.net.shuxing.yifu.common.bean.ContentSys;
import cn.net.shuxing.yifu.common.bean.Country;
import cn.net.shuxing.yifu.common.constant.OssConstant;
import cn.net.shuxing.yifu.common.dto.DateTimeVo;
import cn.net.shuxing.yifu.common.mapper.ContentHelperMapper;
import cn.net.shuxing.yifu.common.mapper.ContentQuestionMapper;
import cn.net.shuxing.yifu.common.util.CommonExample;
import cn.net.shuxing.yifu.common.util.StringUtils;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class ContentHelperService extends ContentService<ContentHelper, ContentHelperMapper> {

    @Autowired
    private OssCommonService ossCommonService;

    @Autowired
    private ContentHelperMapper contentHelperMapper;

    @Override
    protected void complete(ContentHelper bean) {
        if (bean == null)
            return;
        LocalDateTime createTime = bean.getCreateTime();
        DateTimeVo dateTimeVo = new DateTimeVo(createTime);
        bean.setDateTimeVo(dateTimeVo);

        if (StringUtils.hasText(bean.getHelperDetail())) {
            bean.setHelperLinkUrl(ossCommonService.getUrl(OssConstant.ossBucketName, bean.getHelperDetail()));
        }
    }

    public ContentHelper getByInlienLink(String link) {
        CommonExample example = new CommonExample(ContentSys.class);
        example.equals("helperLink", link);
        return getByExampleWithoutComplete(example);
    }

    public List<ContentHelper> selectByClassId(int classId) {
//        ContentHelper contentHelper = new ContentHelper();
//        contentHelper.setHelperClassId(classId);
//        contentHelper.setDeleted(0);
//        return contentHelperMapper.select(contentHelper);
        CommonExample example = new CommonExample(ContentHelper.class);
        example.equals("helperClassId", classId);
        return getsByExampleWithoutComplete(example);
    }
}
